

class DateUtil {
    static dateUtil = new DateUtil()
    static oneDayTime: number = 24 * 60 * 60 * 1000;
    static list: string[] = [];
    static lastDay: any
    /**
      * 
      * @param dateNow :Date类
      * @param intervalDays ：间隔天数
      * @param bolPastTime  ：Boolean,判断在参数date之前，还是之后，
     */
    getDateRange(dateNow: Date, intervalDays: number, bolPastTime: boolean) {
        if (bolPastTime === true) {
            DateUtil.lastDay = new Date(dateNow.getTime() - intervalDays * DateUtil.oneDayTime);
            DateUtil.list.push(formateDate(DateUtil.lastDay));
            DateUtil.list.push(formateDate(dateNow));
        } else {
            DateUtil.lastDay = new Date(dateNow.getTime() + intervalDays * DateUtil.oneDayTime);
            DateUtil.list.push(formateDate(dateNow));
            DateUtil.list.push(formateDate(DateUtil.lastDay));
        }
        return DateUtil.list
    }
}

function formateDate(time: any) {
    let year = time.getFullYear()
    let month = time.getMonth() + 1
    let day = time.getDate()
    if (month < 10) {
        month = '0' + month
    }

    if (day < 10) {
        day = '0' + day
    }
    return year + '-' + month + '-' + day + ''
}

export default DateUtil.dateUtil